#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
    public:
        int removeDuplicates(int A[], int n) {
            if (!A) return 0;
            int slow = 0, fast = 0;                         
            while (fast < n) {
                while (fast < n && A[fast] == A[slow]) fast++;
                if (fast == n) break;
                A[++slow] = A[fast++];
            }
            return slow + 1;
        }
};
//add better code
    int removeDuplicates(int A[], int n) {
        if (n == 0) return 0;
        int index = 0, i = 0;
        while (i < n) {
            A[index] = A[i];
            i++;
            while(A[i] == A[index] && i < n) i++;
            index++;
        }   
        return index;
    } 

// test in 1337 online judge and pass all the test
int main(int argc, char **argv)
{
    Solution mySolution;

    cout << "-----------------Test 1--------------------" << endl;
    int A[] = {1, 1, 1 ,2, 3,4,4,5};
    int result = mySolution.removeDuplicates(A, sizeof(A)/sizeof(int));
    cout << result << endl;

    cout << "-----------------Test 2--------------------" << endl;
    int A1[] = {1, 1, 1 };
    int result1 = mySolution.removeDuplicates(A1, sizeof(A1)/sizeof(int));
    cout << result1 << endl;


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
